package com.ncloud.monitor.zabbix4j.screen;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.monitor.zabbix4j.ZabbixApiException;
import com.ncloud.monitor.zabbix4j.ZabbixApiMethod;

/**
 * @author Suguru Yajima
 */
public class Screen extends ZabbixApiMethod {

    public Screen(String apiUrl, String auth) {
        super(apiUrl, auth);
    }

    public ScreenCreateResponse create(ScreenCreateRequest request) throws ZabbixApiException {
        ScreenCreateResponse response = null;
        request.setAuth(auth);

        JSONObject requestJson = JSON.parseObject(JSON.toJSONString(request));

        try {
            String responseJson = sendRequest(requestJson);

            response = JSON.parseObject(responseJson, ScreenCreateResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScreenDeleteResponse delete(ScreenDeleteRequest request) throws ZabbixApiException {
        ScreenDeleteResponse response = null;
        request.setAuth(auth);

        JSONObject requestJson = JSON.parseObject(JSON.toJSONString(request));

        try {
            String responseJson = sendRequest(requestJson);

            response = JSON.parseObject(responseJson, ScreenDeleteResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScreenUpdateResponse update(ScreenUpdateRequest request) throws ZabbixApiException {
        ScreenUpdateResponse response = null;
        request.setAuth(auth);

        JSONObject requestJson = JSON.parseObject(JSON.toJSONString(request));

        try {
            String responseJson = sendRequest(requestJson);

            response = JSON.parseObject(responseJson, ScreenUpdateResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScreenGetResponse get(ScreenGetRequest request) throws ZabbixApiException {
        ScreenGetResponse response = null;
        request.setAuth(auth);

        JSONObject requestJson = JSON.parseObject(JSON.toJSONString(request));

        try {
            String responseJson = sendRequest(requestJson);

            response = JSON.parseObject(responseJson, ScreenGetResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }
}
